﻿/*
 * ! Ext JS Library 4.0 Copyright(c) 2006-2011 Sencha Inc. licensing@sencha.com
 * http://www.sencha.com/license
 */

Ext.define('HMSDesktop.App', {
    extend: 'Ext.ux.desktop.App',
    init: function () {
        this.callParent();
    },
    getModules: function () {
        return GetWinMenu(this);
    },

    // 开始菜单
    getStartConfig: function () {
        var me = this, ret = me.callParent();

        return Ext.apply(ret, {
            title: '艺苑宾馆管理系统',
            height: 400,
            toolConfig: {
                width: 130,
                items: [{
                    text: '桌面快捷方式',
                    iconCls: 'kcoloredit',
                    scale: 'medium',
                    handler: me.onShortcutSettings,
                    scope: me
                }, {
                    text: '桌面背景',
                    iconCls: 'gnome-settings-theme',
                    scale: 'medium',
                    handler: me.onWallpaperSettings,
                    scope: me
                }, {
                    text: '修改密码',
                    scale: 'medium',
                    iconCls: 'key',
                    handler: me.onChangePwd,
                    scope: me
                }, {
                    text: '帮助',
                    scale: 'medium',
                    iconCls: 'Help_Circle_Blue',
                    scope: me
                }, '-', {
                    text: '重新登录',
                    scale: 'medium',
                    iconCls: 'gnome-keyring-manager',
                    handler: me.onlogOut,
                    scope: me
                }, {
                    text: '退出',
                    scale: 'medium',
                    iconCls: 'logout',
                    handler: me.onExit,
                    scope: me
                }]
            }
        });
    },
    // 桌面背景及右键菜单
    getDesktopConfig: function () {
        var me = this, ret = me.callParent();

        return Ext.apply(ret, {

            wallpaper: this.getSettingWallpaper(),
            wallpaperStretch: true
        });
    },
    getSettingWallpaper: function () {
        var def = '/Admin/js/Kwan/desktop/wallpapers/blue.jpg';
        var cookieWall = getCookie('SettingWallpaper');
        if (cookieWall != null)
            def = cookieWall;
        return def;
    },
    onWallpaperSettings: function () {
        var dlg = new HMSDesktop.WallpaperSettings({
            desktop: this.desktop
        });
        dlg.show();
    },
    onShortcutSettings: function () {
        var dlg = new HMSDesktop.ShortcutSettings({
            desktop: this.getDesktop()
        });
        dlg.show();
    },
    onExit: function () {
        Ext.MessageBox.confirm('操作确认', '确定要退出本系统吗?', function (btn) {
            if (btn == 'yes') {
                var mask = new Ext.LoadMask(Ext.getBody(), { msg: '注销中...', removeMask: true });
                mask.show();
                Ext.Ajax.request({
                    url: 'facade.axd?s_action=Logout',
                    async: false,
                    success: function (response) {
                        var result = Ext.JSON.decode(response.responseText);
                        if (result.success) {
                            window.opener = null;
                            window.open(' ', '_self', ' ');
                            window.close();
                        };

                    }
                });

            }
        }, this);

    },
    onlogOut: function () {
        Ext.MessageBox.confirm('操作确认', '确定要注销当前用户吗?', function (btn) {
            if (btn == 'yes') {
                var mask = new Ext.LoadMask(Ext.getBody(), {
                    msg: '注销中...',
                    removeMask: true
                });
                mask.show();
                Ext.Ajax.request({
                    url: 'facade.axd?s_action=Logout',
                    async: false,
                    success: function (response) {
                        var result = Ext.JSON.decode(response.responseText);
                        if (result.success) {
                            window.location.href = '/ExtLogin.aspx';
                        };

                    }
                });
            }
        }, this);
    },
    onChangePwd: function () {
        var dlg = new HMSDesktop.ChangePwd();
        dlg.show();
    },
    // 任务栏
    getTaskbarConfig: function () {
        var ret = this.callParent();

        return Ext.apply(ret, {
            quickStart: [{
                name: '显示桌面',
                iconCls: 'mymac',
                handler: function () {
                    this.app.getDesktop().showDesktop();
                }
            }, {
                name: '规则排列窗口',
                iconCls: 'pl',
                handler: function () {
                    this.app.getDesktop().cascadeWindows();
                }
            }, {
                name: '关闭所有窗体',
                iconCls: 'Close',
                handler: function () {
                    this.app.getDesktop().closeAllWinows();
                }
            }],
            trayItems: [{
                xtype: 'trayclock',
                flex: 1
            }]
        });
    }

});
